<?php
session_start();

if(dirname($_SERVER['PHP_SELF'])=="\\"){
	define ("ROOT_PATH","");
}else{
	define("ROOT_PATH",dirname($_SERVER['PHP_SELF']));
}
include ("conn.php");
//lay ngon ngu
$lang = (isset($_SESSION["lang"]))?$_SESSION["lang"]:0;
// lay router tu rewrite url
if(isset($_GET["rt"])){
	$rt = $_GET["rt"];
}else{
	$rt = "";
}
?>
<?php
$st1="select * from weblink";
$kq1=mysql_query($st1);
	if(isset($_POST["login"]))
{
$username=$_POST["username"];
$password=$_POST["password"];
$st="select StudentID,StudentName from tblstudent where StudentCode='$username' and StudentPass=md5('$password')";
$kq=mysql_query($st);
$nr=mysql_num_rows($kq);
$row=mysql_fetch_assoc($kq);
if($nr>0)
{			
            $_SESSION["UserIDst"] = $row['StudentID'];	
			$_SESSION["User"] =$row['StudentName'];
}
}
?>
	<?php
	if(isset($_POST["dangky"]))
{

$password=$_POST["pass"];
$image=$_POST["hinh"];
$phone=$_POST["sdt"];
$email=$_POST["email"];
$st=sprintf("update tblstudent set StudentEmail='%s',StudentPhone='%s', StudentImage='%s', StudentPass=md5('%s') where StudentID='%s'",$email,$phone,$image,$password,$_SESSION["UserIDst"]);
$kq=mysql_query($st);
		if($kq!=1)
			{
				?>
				<script language="javascript">
				alert("Chưa sửa được thông tin sinh viên !");
			
				</script>
				<?php
					
			}
			else
			{
				
			   
				?>
				<script language="javascript">
				alert("Sửa thông tin sinh viên thành công!");
				window.location = "/";
				</script>
				<?php
				
			}
}
else {
$st=sprintf("select * from tblstudent where StudentID='%s'",$_SESSION["UserIDst"]);
$kq=mysql_query($st);
$rowstudent=mysql_fetch_assoc($kq);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Đại học thái nguyên</title>
		<link rel="stylesheet" type="text/css" href="css/style.css"/>
		<link rel="stylesheet" type="text/css" href="css/nivo-slider.css"/>
		<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
		<script type="text/javascript" src="js/jquery.nivo.slider.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				var tabActived = $("#tabbed-menu .tabs li.actived");	
				var tabActivedClasses = tabActived.attr("class");
				var ulTabbeds = $("#tabbed-menu .content ul");

				for(var i = 0; i< ulTabbeds.length; i++){
				
					var ulClass = ulTabbeds.eq(i).attr("class");
					if(tabActivedClasses.indexOf(ulClass) != -1){
						ulTabbeds.eq(i).css("display","block");
						break;
					}
				}
				
				$("#tabbed-menu .tabs li").click(function(){
						
							if($(this).attr("class").indexOf("actived") == -1){
								$("#tabbed-menu .tabs li.actived").removeClass("actived");
								$(this).addClass("actived");
								$("#tabbed-menu .content ul").fadeOut(0);
								for(var i = 0; i< ulTabbeds.length; i++){
									var ulClass = ulTabbeds.eq(i).attr("class");
									if($(this).attr("class").indexOf(ulClass) != -1){
										ulTabbeds.eq(i).fadeIn(0);
										break;
									}
								}
							}
				}); 
				$('#slider').nivoSlider();
				$("#langvi").click(function(){
					$.ajax({type:"GET",
							url:"lang.php",
							data:"lang=0",
							success: function(data){						
								window.location.reload();
							}
					});
				});

				$("#langen").click(function(){
					$.ajax({type:"GET",
							url:"lang.php",
							data:"lang=1",
							success: function(data){
								window.location.reload();
							}
					});

				});
			});
			function  showlogin()
			{
				var content="";
				$("#login").css("height","180px"); content=" <form name='frmlogin' action='' method='post'> <div class='field'>User Name <span><input type='text'  value=''"+ "name='username'></span>  </div><div class='field' style=''>Password <span><input type='text'  value='' name='password'></span></div><center><input type='submit' value='đăng nhập' name='login'/></center></form>";
				$("#showlogin").html(content);
				$("#showlogin").css("border-bottom","solid 1px #FFFFFF");
			}
			
  function kt()
	{
	
		with(document.fdangky)
		{
			
			if(email.value=="")
			{
				alert("Chua nhap email");
				email.focus();
				return false;
			}
		
			if(sdt.value=="")
			{
				alert("Chua nhap so dien thoai");
				sdt.focus();
				return false;
			}
		
			if(pass.value=="")
			{
				alert("Chua nhap mat khau");
				pass.focus();
				return false
			}
			if(repass.value=="")
			{
				alert("Chua nhap lai mat khau");
				repass.focus();  
				return false;
			}
			if(repass.value!=pass.value)
			{
				alert("Thong tin pass sai");
				pass.focus();
				return false;
			}
			checkmail=/^\w(\.?[\w-])*@\w(\.?[-\w])*\.[a-z]{2,4}$/i;
			if(checkmail.test(email.value)==false)
			{
				alert("Email khonghop le");
				email.focus();
				return false;
			}
			
			r2=/^0[0-9]{9,10}$/;
			if (r2.test(sdt.value)==false) 
				{
					alert("Nhập sai định dạng số điện thoại !");
					sdt.focus();
					return false;
				}
			
			if(pass.value.length<3 || pass.value.length>32)
				{	
					alert("So ky tu ten dang nhap khong duoc nho hon 3 va khong duoc qua 32");
					pass.focus();
					return false;
				}
			
			
			submit();
			return true;
		}
	}
</script>
        
        <style type="text/css">
		.field{
		width:100%;
		float:left;
		margin-top:5px;
		}
		.field span input
		{
			float:right;
			width:100px;
	    }
		</style>
	</head>
<body>
	

	<div id="header">
			<div id="h-top">
				<div id="logo"><a href="sub.html">
					<img src="images/logo.png" alt="logo" width="186" height="50"/></a>
				</div>
  				<ul id="h-menu">
  					<?php
					// lấy menu gốc
					$sqlRootMenus =sprintf("select * from tblmenu where parent_id = 0 order by tblmenu.order");
					$rootMenusResult= mysql_query($sqlRootMenus) or die(mysql_error());
					//cấp 1
					$i = 0;
					$arrRootMenus = array();
				 	while($row = mysql_fetch_object($rootMenusResult)){
				 		// luuw lại menu gốc cho footer;
				 		$arrRootMenus[] = $row;
				 		$i++;
						echo "<li ".(($i==mysql_num_rows($rootMenusResult)) ? "class='last'" : ""). "><a href='".ROOT_PATH.(($row->url =="") ? "/m/". $row->id : $row->url)."'>".(($lang == 0) ? $row->vi_name : $row->en_name)."</a>";
						$sqlChildMenus1 =sprintf("select * from tblmenu where parent_id = %s", $row->id);
						$childMenusResult1= mysql_query($sqlChildMenus1) or die(mysql_error());
						if(mysql_num_rows($childMenusResult1) >0){
							echo "<ul>";
							//cấp 2
							while($row1 = mysql_fetch_object($childMenusResult1)){
								echo "<li><a href='".ROOT_PATH. (($row1->url =="") ? "/m/". $row1->id : $row1->url)."'>".(($lang == 0) ? $row1->vi_name : $row1->en_name)."</a>";
								$sqlChildMenus2 =sprintf("select * from tblmenu where parent_id = %s", $row1->id);
								$childMenusResult2= mysql_query($sqlChildMenus2) or die(mysql_error());
								if(mysql_num_rows($childMenusResult2) >0){
									echo "<ul>";
									//cấp 3
									while($row2 = mysql_fetch_object($menusResult2)){
										echo "<li><a href='".ROOT_PATH.(($row2->url =="") ? "/m/". $row2->id : $row1->url)."'>".(($lang == 0) ? $row2->vi_name : $row2->en_name)."</a></li>";
									}
									echo "</ul>";
								}
								echo "</li>";
							}
							echo "</ul>";
						}
						echo "</li>";
					}
				?>
				</ul>
				
			</div><!-- end of sub.htmlh-top -->
			<div id="slider">
				<img src="images/slide.jpg" alt="" />
                <a href="http://idgit.com.vn"><img src="images/slide2.jpg" alt="" /></a>
                <img src="images/slide.jpg" alt="" />
                <img src="images/slide2.jpg" alt="" />
			</div><!-- end of sub.htmlslide -->
			<div id="search">
					<div>
						<a href="index.html" id="langen">
							<img src="images/en.png" alt="English"/>
						</a>
						<a href="index.html" id="langvi">
							<img src="images/vi.png" alt="Vietnamese"/>
						</a>
					</div>
					<div>
						<form name="frmSearch" action="" method="post">
							<input type="text" name="keyword" id="txtKeyWord" size="20"/>
							<input type="submit" id="btnSearch" value=""/>
						</form>
					</div>
							
				</div>
			<div id="login">
			  <div class="l-top"> <a href="#" onclick="showlogin()">Login</a> <a href="index.html">Site Map</a> <a href="#"><img src="<?php echo ROOT_PATH?>/images/mail.jpg" alt="Mail"/></a> </div>
			  <div id="showlogin"> <span style="height:30px;color:#00C;font-size:14px">
			    <?php if($_SESSION["UserIDst"]!="") echo "<a href='".ROOT_PATH."/tnu/editinfo.php'>".$_SESSION["User"]."| </a>"."  "."<a href='".ROOT_PATH."/tnu/logout.php'>đăng xuất</a>"; ?>
			    </span> </div>
			  <div class="l-bottom">
			    <div class="a1"> <a href="#">Liên kết website1</a> </div>
			    <div class="a2">
			      <select name="select" onChange="window.location=this.value">
			        <option>--Website liên kết--</option>
			        <?php
							  	
							  while($rowweb=mysql_fetch_array($kq1))
							 {
                              echo "<option value='".$rowweb["url"]."'>" .$rowweb["name"]."</option>";
							 }
							?>
		          </select>
		        </div>
		      </div>
	  </div>
	</div>
        <style type="text/css">
		 /* CSS Document */
.class_cen{
width:630px;
margin:0px;
padding:0px;
float:left;
}
/*trang home*/
#slider1 {
    width: 630px; /* important to be same as image width */
    height: 280px; /* important to be same as image height */
    position: relative; /* important */
	overflow: hidden; /* important */
	background:#FFFFFF
	float:left;
	margin:0px;
}

#slider1Content {
    width: 630px; /* important to be same as image width or wider */
  
	margin:0px;
	float:left;
	
	
}

.slider1Image {
    float: left;
	margin:0px;
	display:block;
	padding:0px;
 
	width:630px;
	height:280px;
	
}

.slider1Image span {
    position: absolute;
	font: 10px Arial, Helvetica, sans-serif;
    width: 630px;
    background-color:#FFF;
    filter: alpha(opacity=70);
    -moz-opacity: 0.7;
	-khtml-opacity: 0.7;
    opacity: 0.7;
    color: #fff;
    display: none;
	margin:0px;
	
	
}
.clear {
	clear: both;
	
}
.slider1Image span strong {
    font-size:14px;
}
.left {
	top:02px;
    left:0px;
	width: 105px !important;
	height: 275px;
	padding:2px;
	display:block;
}
.right {
	right:015px;
	bottom:02px;
	width:105px !important;
	height: 275px;
	padding:2px;
	display:block;
	
	
}
ul { list-style-type: none;}
/*rtang tin tuc*/
#id_tintuc{
width:610px;
margin:0px;
padding:0px;
float:left;

display:block;
clear:both;
}
#id_tintuc_tieude{
width:500px;
height:20px;
float:left;
margin:4px; 
color:#000000;
font-size:14px;
text-indent:12px;
border-bottom-color:#333333;
border-bottom-style:solid;
border-bottom-width:2px;
}
#id_tintuc_tin{
width:600px;
color:#000000;
font-size:12px;
text-indent:12px;
float:left;
margin-bottom:10px;
text-align:justify;
}

/*rtang dang ky thanh vien*/
#id_centop{
width:500px;
height:20px;
margin:0px;
padding:0px;
float:left;
border-bottom-color:#999999;
border-bottom-style:solid;
border-bottom-width:3px;
text-indent:10px;
color:#333333;
font-family:tahoma;
font-size:16px;

}
#id_cen_foter{
width:630px;
margin:0px;
padding:0px;
float:left;
}
#id_cen_foter p{
width:500px;
height:20px;
margin:5px 0px 0px 0;
float:left;
}
#id_cen_foter p label{
width:150px;
float:left;
}
#id_cen_foter p span{
color:#FF0000;
}
/*trang dang nhap*/

		</style>
	<div id="all">
		
		<div id="main">
        <div class="class_cen">
		<div  id="id_centop" style="margin:auto">THAY ĐỔI THÔNG TIN  </div>
		<div id="id_cen_foter">
		
		<form action="xlchange.php" method="post" name="fdangky" enctype="multipart/form-data" >
		<fieldset style="margin:10px; padding:10px;">
			<legend style="color:#FF0000; font:tahoma; font-size:14px;">Thông tin cá nhân </legend>
            <div style="float:left;width:30%">
            <img src="<?php  echo ROOT_PATH."/tnu/imagestudent/".$rowstudent['StudentImage']; ?>" width="100" height="120px" name="img" >
            </div>
			<div style="float:left;width:70%">
				<p><label>Email :</label><input type="text" value="<?php  echo $rowstudent['StudentEmail']; ?>" name="email"/></p>	
				<p><label>Số điện thoại :</label><input type="text"  value="<?php echo $rowstudent['StudentPhone']; ?>"  name="sdt"/></p>
     			<p><label>Hình :</label><input type="file"  value="" name="hinh"/></p>
				<p><label>Mật khẩu mới:</label><input type="password" value=""  name="pass"/></p>
				<p><label>Nhập lại mật khẩu :</label><input type="password"  name="repass"/></p>
				<p  style="margin-left:200px; margin-top:5px; ">  <input type="button" name="dangky" value="Sửa thông tin" onclick=" return kt()" />&nbsp;&nbsp;<input type="reset" value="nhập lại" /></p>		
                </div>	
		</fieldset>	
		</form>
		
		
		
		

		</div>
	</div>
		</div>
		<div id="footer" style="float:left">
			<div id="f-menu">
				<ul>
					<?php foreach($arrRootMenus as $rootMenu){
						if($lang ==0){
							echo "<li><a href='".ROOT_PATH.(($rootMenu->url=="")? "/m/".$rootMenu->id: $rootMenu->url)."'>".$rootMenu->vi_name."</a></li>";
						}else{
							echo "<li><a href='".ROOT_PATH.(($rootMenu->url=="")? "/m/".$rootMenu->id: $rootMenu->url)."'>".$rootMenu->en_name."</a></li>";
						}
					}?>
				</ul>
			</div>
			<div id="copyright">
				Bản quyền thuộc về khoa quốc tế đại học Thái Nguyên<br/>
				Copyright &copy; 2011 <a href="http://idgit.com.vn">Idea Development Group</a>
			</div>
			
		</div>
	</div>
</body>
</html>